<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Personinfo;

/**
 * PersoninfoSearch represents the model behind the search form about `app\models\Personinfo`.
 */
class PersoninfoSearch extends Personinfo
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['stu_id', 'stu_name', 'password_hash', 'card_id', 'used_name', 'nation', 'political', 'address', 'religion', 'height', 'maritial_status', 'blood_type', 'telephone', 'qq', 'blank', 'blank_num'], 'safe'],
            [['sex'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Personinfo::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        	'pagination' => [
        				'pageSize' => 1000,
        		],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'sex' => $this->sex,
        ]);

        $query->andFilterWhere(['like', 'stu_id', $this->stu_id])
            ->andFilterWhere(['like', 'stu_name', $this->stu_name])
            ->andFilterWhere(['like', 'password_hash', $this->password_hash])
            ->andFilterWhere(['like', 'card_id', $this->card_id])
            ->andFilterWhere(['like', 'used_name', $this->used_name])
            ->andFilterWhere(['like', 'nation', $this->nation])
            ->andFilterWhere(['like', 'political', $this->political])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'religion', $this->religion])
            ->andFilterWhere(['like', 'height', $this->height])
            ->andFilterWhere(['like', 'maritial_status', $this->maritial_status])
            ->andFilterWhere(['like', 'blood_type', $this->blood_type])
            ->andFilterWhere(['like', 'telephone', $this->telephone])
            ->andFilterWhere(['like', 'qq', $this->qq])
            ->andFilterWhere(['like', 'blank', $this->blank])
            ->andFilterWhere(['like', 'blank_num', $this->blank_num]);
            

        return $dataProvider;
    }
}
